package com.yunst.net.protocol;

import com.yunst.net.message.Message;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

/**
 * @author yunst
 * @date 2022/12/31
 */
public class MessageEncode extends MessageToByteEncoder<Message> {
    protected void encode(ChannelHandlerContext channelHandlerContext, Message message, ByteBuf byteBuf) throws Exception {
        System.out.println("开始编码消息,"+message.toString());
        byteBuf.writeInt(message.getLen());
        byteBuf.writeInt(message.getMessageType());
        byteBuf.writeBytes(message.getContent());
    }
}
